Fixed compiler errors on incorrect [SerializeField] attributes ...#36
Fixed compiler errors on incorrect [SerializeField] attributes ...#36atcarter714 wants to merge 2 commits intosideeffects:Houdini21.0from
Conversation
The C# [SerializeField] attribute in Unity is only allowed on fields, not the get/set methods of a property, therefore when serializing the backing field of an auto-property (implicit backing field generated by Roslyn), it is necessary to use the `field:` specifier to target that generated field:
[SerializeField] public int Counter { get; set; } //! ERROR
[field: SerializeField] public int Counter { get; set; } //! OK
|
You can attach other kinds of attributes (which have the protected int _count ;
public int Counter { //! Aggressive inlining (0x100):
[MethodImpl(0x100)] get => _count ;
[MethodImpl(0x100)] set => _count = value ;
}(And there are of course other specifiers, like EDIT :: Doubled back to delete that dead attribute on line 598 and gave an explanation (has an explicit field already serialized) ... |
Line 598 actually needs no `SerializeFieldAttribute` ... I overlooked the explicit field already tagged with it right above it.
The C#
[SerializeField]attribute in Unity is only allowed on fields, not theget/setmethods of a property, therefore when serializing the backing field of an auto-property (implicit backing field generated by Roslyn), it is necessary to use thefield:specifier to target that generated field: